<template>
  <el-form :model="form" class="planForm" ref="form" label-width="200px" :rules="rules">
    <el-form-item label="考评方案名称" prop="moralityPlanName">
      <el-input v-model="form.moralityPlanName" placeholder="请输入考评方案名称" />
    </el-form-item>
    <el-form-item label="方案周期" prop="moralityCycleId">
      <el-select clearable style="width: 100%" v-model="form.moralityCycleId" placeholder="请选择">
        <el-option
          v-for="(item,index) in selectData"
          :key="index"
          :value="item.moralityCycleId"
          :label="item.moralityCycleName"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="考评流程是否有党支部环节" prop="branchStep">
      <el-radio-group v-model="form.branchStep">
        <el-radio :label="0">否</el-radio>
        <el-radio :label="1">是</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="方案状态" prop="state">
      <el-select clearable style="width: 100%" v-model="form.state">
        <el-option :value="1" label="暂停" />
        <el-option :value="2" label="启用" />
        <el-option :value="3" label="到期" />
        <el-option :value="4" label="作废" />
      </el-select>
    </el-form-item>
  </el-form>
</template>

<script>
import { cycleAll } from '@/api/morality'

export default {
  data() {
    return {
      form: {
        moralityPlanName: null,
        moralityCycleId: null,
        branchStep: null,
        state: null
      },
      rules: {
        moralityPlanName: [{ required: true, message: '请输入考评方案名称', trigger: 'blur' }],
        moralityCycleId: [{ required: true, message: '请选择方案周期', trigger: 'blur' }],
        branchStep: [{ required: true, message: '请选择考评流程是否有党支部环节', trigger: 'blur' }],
        state: [{ required: true, message: '请选择状态', trigger: 'blur' }]
      },
      selectData: [],
      type: this.$route.params.type
    }
  },
  async mounted() {
    cycleAll().then(res => {
      console.log('cycleAll res', res)
      this.selectData = res.data
    })
  },
  methods: {
    setObj(obj) {
      delete obj.moralityPlanItemList
      delete obj.moralityPlanItemList1
      delete obj.moralityPlanTargetList
      this.form = Object.assign({}, obj)
    },
    postData() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // this.$emit('listData', data)
          this.$emit('postData', true, this.form, 1)
          return false
        }
        this.$emit('notSubmit', 1)
      })
    }
  }
}
</script>
